//
// Created by 86131 on 2023/9/12.
//
//
// Created by 86131 on 2023/9/11.
//
#include <iostream>
#include <stdio.h>
using namespace std;
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;//存储结点数据
    PtrToNode   Next = nullptr;//指向下一个结点的指针
    int sb=0;
};
typedef PtrToNode List;//定义单链表类型;
List Read(); /* 细节在此不表 */
void Print( List L ); /* 细节在此不表；空链表将输出NULL */

int out1(List L1,int X);
int main()
{
    List L1, L2, L;
    int x;
    cin>>x;
    L=Read();
    int s = out1(L,x);
    if(s==-1){cout<<"NULL";return 0;}
    cout<<s;
    return 0;
}
List Read(){
    int n;//
    cin>>n;//输入要读入的数据个数
    List first  = (List)malloc(sizeof (List)) ;
    first->sb=0;
    Node *node_temp = first;
    while(n>=0){
        Node *node = new Node;
        node->Data=n;
        node_temp->Next = node;
        node_temp = node;
        first->sb++;
        // cout<<first->sb;
        cin>>n;
    }
    return first;
}
void Print(List L){
    if(L== nullptr){cout<<"NULL";
        return;}
    L = L->Next;
    while(L!=nullptr){
        cout<<L->Data<<" ";
        L= L->Next;
    }

}
/* 你的代码将被嵌在这里 */
int out1(List L1,int X){
    List p1 = L1->Next;
    if(X>L1->sb){return -1;}
    int a = L1->sb-X;
    for(int i=0;i<a;i++){
        p1=p1->Next;

    }
    return p1->Data;
}